<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>青青草原用户系统</title>
    <style>
        /* 保留之前的通用样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Arial, sans-serif;
        }

        .container {
            width: 100vw;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            position: relative;
            overflow: hidden;
            background-color: rgba(139, 230, 180, 0.1);
        }

        /* 新增注册模态框样式 */
        .modal {
            display: none;
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.5);
            justify-content: center;
            align-items: center;
        }

        .register-container {
            background: rgba(255, 192, 203, 0.95);
            padding: 2rem;
            border-radius: 1.5rem;
            width: 100%;
            max-width: 400px;
            box-shadow: 0 15px 30px rgba(86, 219, 177, 0.3);
        }

        .switch-form {
            text-align: center;
            margin-bottom: 1.5rem;
            cursor: pointer;
            color: #82d86a;
        }

        .switch-form:hover {
            color: #ff459e;
        }

        /* 其他保留的登录样式 */
        .login-bg {
            position: absolute;
            top: 40px;
            left: 40px;
            z-index: -1;
            opacity: 0.1;
            animation: rotate 20s linear infinite;
            width: 400px;
            height: 400px;
        }

        @keyframes rotate {
            from { transform: rotate(0deg); }
            to { transform: rotate(360deg); }
        }

        .form-title {
            text-align: center;
            color: white;
            margin-bottom: 1.5rem;
            font-size: 1.8rem;
        }

        .form-group {
            margin-bottom: 1.2rem;
        }

        label {
            display: block;
            margin-bottom: 0.5rem;
            color: #78e4c1;
        }

        input[type="text"],
        input[type="password"],
        input[type="email"] {
            width: 100%;
            padding: 0.9rem;
            border: 2px solid #8ff996;
            border-radius: 0.6rem;
            background-color: rgba(255, 255, 255, 0.95);
            transition: border-color 0.3s ease;
        }

        input:focus {
            border-color: #64ee99;
            outline: none;
        }

        button {
            width: 100%;
            padding: 1rem;
            border: none;
            border-radius: 0.6rem;
            cursor: pointer;
            font-size: 1.1rem;
            transition: all 0.3s ease;
        }

        #denglu {
            background-color: #72f37a;
            color: white;
        }

        #denglu:hover {
            background-color: #87e885;
            transform: translateY(-2px);
        }

        #zhuce {
            background-color: #9ee592;
            color: #90cd9d;
            margin-top: 1rem;
        }

        #zhuce:hover {
            background-color: #58e489;
        }

        .message {
            padding: 1rem;
            border-radius: 0.5rem;
            text-align: center;
            margin-top: 1rem;
            display: none;
        }

        .success {
            background-color: #98fb98;
            color: #47df47;
        }

        .error {
            background-color: #ffcccc;
            color: #8fe899;
        }

        @media (max-width: 768px) {
            .login-bg {
                width: 300px;
                height: 300px;
                top: 20px;
                left: 20px;
            }
            
            .form-title {
                font-size: 1.5rem;
            }
        }
    </style>
</head>
<body>
    <!-- 登录表单 -->
    <div class="container">
        <img src="https://q0.itc.cn/q_70/images03/20241220/e9f35e2555644895a714f14df31b9ed1.gif" 
             alt="Loading animation" 
             class="login-bg">
        
        <form class="login-form" id="loginForm">
            <h1 class="form-title">欢迎使用青青草原系统</h1>
            
            <div id="loginMessage"></div>

            <div class="form-group">
                <label for="username">用户名：</label>
                <input type="text" id="username" required minlength="2" maxlength="10">
            </div>

            <div class="form-group">
                <label for="password">密码：</label>
                <input type="password" id="password" required>
            </div>

            <div class="form-actions">
                <button type="submit" id="denglu">立即登录</button>
                <button type="button" id="zhuce">注册新账号</button>
            </div>
        </form>
    </div>

    <!-- 注册模态框 -->
    <div class="modal" id="registerModal">
        <div class="register-container">
            <div class="switch-form" onclick="toggleRegister()">← 返回登录</div>
            <h2 class="form-title">注册新账号</h2>
            
            <div id="registerMessage"></div>

            <div class="form-group">
                <label for="newUsername">用户名：</label>
                <input type="text" id="newUsername" required minlength="2" maxlength="10">
            </div>

            <div class="form-group">
                <label for="email">电子邮箱：</label>
                <input type="email" id="email" required>
            </div>

            <div class="form-group">
                <label for="newPassword">密码：</label>
                <input type="password" id="newPassword" required minlength="6">
            </div>

            <div class="form-group">
                <label for="confirmPassword">确认密码：</label>
                <input type="password" id="confirmPassword" required>
            </div>

            <div class="form-group">
                <label>性别：</label>
                <div class="gender-group">
                    <label><input type="radio" name="sex" value="male" required> 先生</label>
                    <label><input type="radio" name="sex" value="female"> 女士</label>
                </div>
            </div>

            <div class="form-actions">
                <button type="button" onclick="registerUser()" id="submitReg">完成注册</button>
            </div>
        </div>
    </div>

    <script>
        // 表单切换功能
        function toggleRegister() {
            const modal = document.getElementById('registerModal');
            const loginContainer = document.querySelector('.container');
            modal.style.display = modal.style.display === 'flex' ? 'none' : 'flex';
            loginContainer.classList.toggle('blurred');
        }

        // 注册验证逻辑
        function registerUser() {
            const messages = document.getElementById('registerMessage');
            const username = document.getElementById('newUsername').value;
            const email = document.getElementById('email').value;
            const password = document.getElementById('newPassword').value;
            const confirmPassword = document.getElementById('confirmPassword').value;

            // 清除旧消息
            messages.style.display = 'none';
            messages.className = 'message';

            // 验证用户名
            if (username.includes('羊羊')) {
                showMessage('名字不要取那么怪', 'error');
                return;
            }
            
            if (username.startsWith('坂田')) {
                showMessage('青青草原没有坂田这个姓', 'error');
                return;
            }

            // 密码验证
            if (password !== confirmPassword) {
                showMessage('两次输入密码不一致', 'error');
                return;
            }

            if (password.length < 6) {
                showMessage('密码至少需要6位', 'error');
                return;
            }

            // 特殊后缀处理
            if (username.endsWith('次郎')) {
                username = username.replace('次郎', '太狼');
            }

            // 模拟注册成功
            showMessage(`注册成功！欢迎${username}加入青青草原！`, 'success');
            
            // 自动登录
            document.getElementById('username').value = username;
            document.getElementById('password').value = password;
            document.getElementById('loginForm').dispatchEvent(new Event('submit'));
        }

        // 显示消息函数
        function showMessage(text, type) {
            const messages = document.getElementById('registerMessage');
            messages.innerText = text;
            messages.className = `message ${type}`;
            messages.style.display = 'block';
        }

        // 登录表单提交
        document.getElementById('loginForm').addEventListener('submit', function(e) {
            e.preventDefault();
            const messages = document.getElementById('loginMessage');
            
            // 简单验证示例
            if (this.checkValidity()) {
                showMessage('正在登录...', 'success');
                setTimeout(() => {
                    messages.style.display = 'none';
                    alert('登录成功！');
                }, 1000);
            }
        });

        // 绑定注册按钮事件
        document.getElementById('zhuce').addEventListener('click', () => {
            document.getElementById('registerModal').style.display = 'flex';
        });
    </script>
</body>
</html>